package com.atguigu.oss.controller;

import com.atguigu.commonutils.R;
import com.atguigu.oss.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Api(description="图片上传")  /*swagger上面的提示*/
@RestController
@RequestMapping("/eduoss/fileoss")
//原来需要在Controller上面加上@CrossOrigin解决跨域问题，现在gateway已经处理了  /*避免跨域问题*/
public class OssController {

    @Autowired
    private OssService ossService;

    /*上传头像的方法*/
    @ApiOperation(value = "图片上传方法")
    @PostMapping
    public R uploadOssFile(MultipartFile file) throws IOException {
        /*获取上传文件，MultipartFile*/
        /*返回的是url路径*/
        String url=ossService.uploadFileAvatar(file);
        return R.ok().data("url",url);
    }
}